<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="单据编号">
              <a-input placeholder="请输入单据编号" v-model="queryParam.documentNo"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="申请人">
              <select-user-by-dep placeholder="请选择申请人" :multi="false" v-model="queryParam.handlerId"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目名称">
              <select-project-input  v-model="queryParam.projectId" placeholder="请输入选择项目" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="车牌号">
              <select-car-num-input placeholder="请选择车牌号" v-model="queryParam.carId"/>
            </a-form-item>
          </a-col>
          <!-- <template v-if="toggleSearchStatus"></template> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12" :key="index"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;"><a-icon type="setting" :style='iconStyle'/></a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;margin-top: 25px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:1300}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">
        <a slot="documentNo" slot-scope="text, record" @click="getDetail(record)">{{ text }}</a>
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <span slot="action" slot-scope="text, record">
          <template v-if="record.checkStatus==2 && record.isDriver == '1'">
            <a-button type="primary" size="small" @click="examine(record)" :disabled="isDisabledAuth('erpCarUsing:driver')" style="margin-right: 5px">驾驶员</a-button>
            <a-divider type="vertical"/>
          </template>
          <template v-if="record.bpmStatus !== '1'">
            <a-button type="primary" size="small" @click="handleTrack(record)" :disabled="isDisabledAuth('erpCarUsing:viewTrack')">审批进度</a-button>
          </template>
        </span>
        <span slot="projectId" slot-scope="text, record">
          <a @click="onDetail(record.projectId)">{{ text }}</a>
        </span>
      </a-table>
    </div>
    <a-modal
      title="请选择驾驶人"
      :visible="modalvisible"
      @ok="handleOKk"
      @cancel="modalvisible = false"
    >
      <select-user-by-dep placeholder="请选择驾驶人" :multi="false" v-model="driver" :disabled="driverFlag"/>
    </a-modal>
    <!-- 项目详情开始 -->
    <erp-project-report-modal  ref="prejectForm"></erp-project-report-modal>
    <!-- 项目详情结束 -->
    <erp-car-using-modal ref="modalForm" @ok="modalFormOk"></erp-car-using-modal>
    <bpm-biz-task-deal-modal ref="taskDealModal" :path="path" :formData="formData" @ok="handleOk"></bpm-biz-task-deal-modal>
    <bpm-process-track-modal ref="bpmProcessTrackModal"></bpm-process-track-modal>
    <biz-task-notify-modal ref="taskNotifyModal"></biz-task-notify-modal>
    <biz-task-notify-me-modal ref="taskNotifyMeModal"></biz-task-notify-me-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import {JeecgBpmListMixin} from '@/mixins/JeecgBpmListMixin'
import BpmBizTaskDealModal from '@/views/modules/bpmbiz/common/BpmBizTaskDealModal.vue';
import BpmProcessTrackModal from '@/views/modules/bpmbiz/common/BpmProcessTrackModal.vue';
import BizTaskNotifyModal from '@/views/modules/bpmbiz/common/BizTaskNotifyModal.vue';
import BizTaskNotifyMeModal from '@/views/modules/bpmbiz/common/BizTaskNotifyMeModal.vue';
import ErpCarUsingModal from './modules/ErpCarUsingModal'
import { getAction } from '@/api/manage'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
import SelectProjectInput from '@/views/scy/components/SelectProjectInput'
import SelectCarNumInput from '../carmaintenance/modules/SelectCarNumInput';
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
import ErpProjectReportModal from '@/views/erp/report/project/modules/ErpProjectReportModal'

export default {
    name: 'ErpCarUsingExamineList',
    mixins:[JeecgBpmListMixin,mixinDevice, DisabledAuthFilterMixin],
    components: {
      SelectCarNumInput,
      ErpCarUsingModal,
      BpmBizTaskDealModal,
      BpmProcessTrackModal,
      BizTaskNotifyModal,
      BizTaskNotifyMeModal,
      SelectUserByDep,
      SelectProjectInput,
      ErpProjectReportModal
    },
    data () {
      return {
        description: '用车申请清单管理页面',
        //表头
        columns:[],
        //列设置
        settingColumns:[],
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'单据编号',
            align:"center",
            dataIndex: 'documentNo',
            width:200,
            ellipsis: true,
            scopedSlots: { customRender: 'documentNo' },
          },
          {
            title:'申请人',
            align:"center",
            width:100,
            ellipsis: true,
            dataIndex: 'handlerId_dictText',
          },
          {
            title:'业务团队',
            align:"center",
            width:300,
            ellipsis: true,
            dataIndex: 'businessUnit_dictText',
          },
          {
            title:'项目名称',
            align:"center",
            width:400,
            ellipsis: true,
            scopedSlots: { customRender: 'projectId' },
            dataIndex: 'projectId_dictText',
          },
          {
            title:'用车类型',
            align:"center",
            width:200,
            ellipsis: true,
            dataIndex: 'usingType_dictText',
          },
          {
            title:'事由',
            align:"center",
            width:200,
            ellipsis: true,
            dataIndex: 'subjectMatter',
          },
          {
            title:'是否已还车',
            align:"center",
            width:100,
            ellipsis: true,
            dataIndex: 'isReturnCar_dictText',
          },
          {
            title:'流程状态',
            align:"center",
            width:100,
            ellipsis: true,
            dataIndex: 'bpmStatus_dictText',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:180,
            scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action' }
          }
        ],
        url: {
          list: "/api/erp/erpcarusing/erpCarUsing/checkList?checkStatus=2",
          auditAddDriver: "/api/erp/erpcarusing/erpCarUsing/auditAddDriver",
          queryProjectReportById: '/api/erp/project/report/erpProjectReport/queryById',
        },
        //代码生成后需手动设置流程编码
        flowCode: 'onl_erp_car_using',
        formUrl: "/oa/erpcarusing/modules/ErpCarUsingForm",
        formUrlMobile: "",
        dictOptions:{},
        superFieldList:[],
        modalvisible: false,
        driver: '',
        recordId: '',
        driverFlag: false
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      //查看详情
      getDetail(record) {
        this.$refs.modalForm.edit(record);
        this.$refs.modalForm.title = '详情';
        this.$refs.modalForm.disableSubmit = true;
      },
      examine(record){
        this.modalvisible = true
        this.recordId = record.id
        this.driver = record.driver
        if(record.isReturnCar == "1") {
          this.driverFlag = true
        } else {
          this.driverFlag = false
        }
      },
      handleOKk(){
        let that = this;
        let param;
        param = {
          id: this.recordId,
          driver: this.driver
        }
        that.loading = true;
        getAction(that.url.auditAddDriver, param).then((res) => {
          if (res.success) {
            that.$message.success(res.message);
          } else {
            that.$message.warning(res.message);
          }
          this.modalvisible = false
          this.loadData(1)
        }).finally(() => {
          that.loading = false;
          this.modalvisible = false
        });
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'documentNo',text:'单据编号',dictCode:''})
        fieldList.push({type:'string',value:'applyUser',text:'申请人',dictCode:''})
        fieldList.push({type:'string',value:'applyUnit',text:'申请单位',dictCode:''})
        fieldList.push({type:'string',value:'usingType',text:'用车类型',dictCode:''})
        fieldList.push({type:'string',value:'businessUnit',text:'业务单位',dictCode:''})
        fieldList.push({type:'string',value:'projectName',text:'项目名称',dictCode:''})
        fieldList.push({type:'string',value:'isDriver',text:'是否需要驾驶员',dictCode:''})
        fieldList.push({type:'date',value:'usingStartTime',text:'用车日期'})
        fieldList.push({type:'date',value:'usingEndTime',text:'预计归还日期'})
        fieldList.push({type:'string',value:'subjectMatter',text:'事由',dictCode:''})
        fieldList.push({type:'string',value:'driver',text:'驾驶员',dictCode:''})
        fieldList.push({type:'string',value:'isReturnCar',text:'是否已还车',dictCode:''})
        fieldList.push({type:'date',value:'returnCarTime',text:'还车日期'})
        fieldList.push({type:'string',value:'remark',text:'备注',dictCode:''})
        fieldList.push({type:'string',value:'fileInfo',text:'附件信息',dictCode:''})
        fieldList.push({type:'string',value:'handlerId',text:'经办人',dictCode:''})
        fieldList.push({type:'date',value:'createTime',text:'创建日期'})
        fieldList.push({type:'int',value:'auditStatus',text:'审核状态',dictCode:''})
        this.superFieldList = fieldList
      },
      // 穿透项目底表
      onDetail(id) {
        const that = this
        this.$nextTick(() => {
          getAction(this.url.queryProjectReportById, { id }).then((res) => {
            if (res.success) {
              const model = res.result
              that.$refs.prejectForm.getDetail(model);
              that.$refs.prejectForm.title = '项目一览表';
            }
          })
        })
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
